import sys
from PySide6.QtWidgets import QDialog
from ui.ui_dialog import Ui_Dialog


class Dialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.buttonBox.rejected.connect(self.onClickRejected)
        self.ui.buttonBox.accepted.connect(self.onClickAccepted)

    def onClickRejected(self):
        sys.exit(0)

    def onClickAccepted(self):
        if self.ui.IdEdit.text() == '' or self.ui.KeyEdit.text() == '':
            self.ui.IdEdit.setStyleSheet('border: 1px solid red;')
            self.ui.KeyEdit.setStyleSheet('border: 1px solid red;')
            return
        self.__dict = {'id': self.ui.IdEdit.text(), 'key': self.ui.KeyEdit.text()}
        self.accept()  # 触发 exec() 返回 QDialog.Accepted

    def getDialogInfo(self):
        return self.__dict
